package com.gitee.wsl.common.ui.ext.path

import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Path
import com.gitee.wsl.math.Math.TWO_PI
import kotlin.math.sin

fun Path.buildWaveLinePath(bound: Rect,x:Float = bound.left, waveLength:Float, animProgress: Float,extent:Float=1f): Path {
    //asAndroidPath().rewind()
    //moveTo(bound.left, bound.height) // 不能放这里
    var pointX = bound.left
    while (pointX < bound.right) {
        val offsetY = (bound.bottom + sin(((x - bound.left) / waveLength) * TWO_PI + (TWO_PI * animProgress)) * extent).toFloat()
        if(x == bound.left) {
            moveTo(bound.left, offsetY)
        }
        lineTo(x, offsetY)
        pointX += 1F
    }
    return this
}
